

(function($){
   var MyPlugin = function(element)
   {
       var elem = $(element);
       var old_child_class = elem.children().attr('class');
       var old_class = elem.attr('class');
       var position = elem.position();
       var n = 0;
       
       if (old_class != '' && typeof old_class != 'undefined')
           old_class = old_class + ' ';
       else
           old_class = '';
       
       if (old_child_class != '' && typeof old_child_class != 'undefined')
           old_child_class = old_child_class + ' ';
       else
           old_child_class = '';
       
       elem.attr('class', old_class + 'slide-set');
       elem.children().attr('class', old_child_class + 'slide');
       
       old_child_class = elem.children().each(function(){
           n++;
           $(this).attr('id', elem.attr('id')+'-slide-'+n);
       });
       
       elem.append('<ul class="slide-button-set"></ul>');
       var slide_button_set =  elem.find('ul.slide-button-set');
       
       for(var i=1; i <= n; i++) {
           slide_button_set.append('<li id="'+elem.attr('id')+'-slide-button-'+i+'"><a href="#"></a></li>');
       }
       
       var top = parseInt(elem.position().top.toString());
       var left = parseInt(elem.position().left.toString());
       
       
       /*
       slide_button_set.position({top: top + elem.height() - slide_button_set.height() - 10,
                                left: left + elem.width() - slide_button_set.width() - 10});
       */

       
   };

   $.fn.myplugin = function()
   {
       return this.each(function()
       {
           var element = $(this);
          
           // Return early if this element already has a plugin instance
           if (element.data('myplugin')) return;

           var myplugin = new MyPlugin(this);

           // Store plugin object in this element's data
           element.data('myplugin', myplugin);
       });
   };
})(jQuery);
